﻿using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using NPOI.POIFS.FileSystem;
using NPOI.SS.UserModel;
/// <summary>
/// Summary description for ClassName
/// </summary>
public class ExcelManager
{
    public static HSSFWorkbook hssfWB;
    public ExcelManager()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    
    public static string Template{get;set;}
    
    
    public static MemoryStream WriteToStream(HSSFWorkbook wb){
        MemoryStream ms = new MemoryStream();
        wb.Write(ms);
        return ms;
    }
    
    public static void WriteToFile(string path,HSSFWorkbook wb){
       FileStream file = new FileStream(path,FileMode.Create); 
       wb.Write(file);
       file.Close();
    }
    
  
    
    public static HSSFWorkbook InitializeWB(String info){
        try{
         //  if(Template!=string.Empty){  
            FileStream fs =   new FileStream(Template,FileMode.Open,FileAccess.Read);
            hssfWB = new HSSFWorkbook(fs,true);
           // }else{
             //   hssfWB = new HSSFWorkbook();
            //}
        }catch(Exception e){
            throw e;
        }
       
         
        
        ////create a entry of DocumentSummaryInformation
        DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
        dsi.Company = "ABSCBN";
        hssfWB.DocumentSummaryInformation = dsi;

        ////create a entry of SummaryInformation
        SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
        si.Subject = info;
        hssfWB.SummaryInformation = si;
        
        return hssfWB;
    }
    
}
